from django.db import models
from django.contrib.auth.models import User

# variables for this models file
wordLen=15
titleLen=30
paragraphLen=150

CHARACTER = 1
OX = 2
WAGON = 3
# Start class definitons 

# not talked about
class RandomEvent(models.Model):
    name = models.CharField(max_length=wordLen)
    probability = models.DecimalField(max_digits=5,decimal_places=4)
    def __unicode__(self):
        return self.name
    class Meta:
        abstract = True
    
        
class OptionHolder(models.Model):
    pass
        
class ItemHolder(models.Model):
    pass
   
class Ailment(RandomEvent):
    message = models.CharField(max_length=paragraphLen)
    minHealth = models.IntegerField()
    maxHealth = models.IntegerField()
    def __unicode__(self):
        return "Ailment:" + self.message
    
class Profession(OptionHolder):
    description = models.CharField(max_length=paragraphLen)
    name = models.CharField(max_length=wordLen)
    def __unicode__(self):
        return self.name

class Party(ItemHolder):
    paceChoices = (
        (3,'Grueling'),
        (2,'Brisk'),
        (1,'Slow')
    )
    rationChoices = (
        (3,'Filling'),
        (2,'Normal'),
        (1,'Meager')
    )
    distanceFromStart = models.DecimalField(max_digits=4,decimal_places=3)
    pace = models.IntegerField(choices=paceChoices)
    date = models.DateField(null=True)
    profession = models.ForeignKey(Profession)
    rations = models.IntegerField(choices=rationChoices)
    game = models.ForeignKey('TravelGame')
    def __unicode__(self):
        return 'Party with profession of: ' + self.profession.name

class Member(models.Model):
    health = models.IntegerField()
    party = models.ForeignKey(Party)
    name = models.CharField(max_length=titleLen)
    status = models.ForeignKey(Ailment, blank=True, null=True)
    isMain = models.BooleanField()
    memberChoices = (
        (CHARACTER,'Traveler'),
        (OX,'Ox'),
        (WAGON,'Wagon')
    )
    weightChoices = (
        (CHARACTER, 0),
        (OX, 0),
        (WAGON,4000)
    )
    carryWeight = models.IntegerField(choices=weightChoices)
    kind = models.IntegerField(choices=memberChoices,blank=False)
    def __unicode__(self):
        return self.name
    
class Item(models.Model):
    weight = models.IntegerField()
    name = models.CharField(max_length=wordLen)
    quantity = models.IntegerField()
    description = models.CharField(max_length=paragraphLen)
    maxQuantity = models.IntegerField()
    party = models.ForeignKey(Party)
    cost = models.DecimalField(max_digits=4,decimal_places=2)
    def __unicode__(self):
        return self.name
    
    
class Option(models.Model):
    holder = models.ForeignKey(OptionHolder)
    name = models.CharField(max_length=wordLen)
    displayName= models.CharField(max_length=titleLen)
    value = models.TextField()  
    def __unicode__(self):
        return self.displayName
    

#class Map(models.Model):
#    #figure out map an landmark and travel game relationship
#    pass

class Landmark(OptionHolder):
    distanceFromStart = models.DecimalField(max_digits=4,decimal_places=3)
    name = models.CharField(max_length = titleLen)
    def __unicode__(self):
        return self.name
    
# talk about later
class TravelGame(models.Model):
    player = models.ForeignKey(User)

# talk about later
class OTG(TravelGame):
    pass ###TODO figure out naming convention for instances of other classes

        
class River(Landmark):
    pass
        
class FortTown(Landmark):
    pass
        
class NaturalWonder(Landmark):
    pass

class NormalLocation(Landmark): 
    pass
    
class Wagon(Member):
    brokenAxle = models.BooleanField()
    brokenWheel = models.BooleanField()
    def __unicode__(self):
        return "Wagon"



#class Robbery(randomEvent):
#    pass

#class InclementWeather(randomEvent):
#    pass

# Needs to be a def in a separate file?
#class REH(models.Model):
#    randomEvents = models.ForeignKey(randomEvent)
